import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  
  { path: '/login', component: () => import('@/views/pages/login'), name: 'login', meta: { title: '登录' } },
  {
    path: '/',component: () => import('@/views/main'), name: 'main', meta: { title: '主入口布局' }, redirect: { name: 'home' },
    children: [
      { path: '/home', component: () => import('@/views/modules/home'), name: 'home', meta: { title: '幸运大抽奖管理平台' } },
      { path: '/manage', component: () => import('@/views/modules/manage'), name: 'manage', meta: { title: '经营统计' } },
      { path: '/user', component: () => import('@/views/modules/user'), name: 'user', meta: { title: '我的' } },
      { path: '/merchant', component: () => import('@/views/modules/merchant'), name: 'merchant', meta: { title: '商户信息' } },
      { path: '/product', component: () => import('@/views/modules/product'), name: 'product', meta: { title: '商品信息' } },
      { path: '/useInfo', component: () => import('@/views/modules/useInfo'), name: 'userInfo', meta: { title: '账户详情' } },
      { path: '/older', component: () => import('@/views/modules/older'), name: 'older', meta: { title: '订单详情' } },
      { path: '/winnInfo', component: () => import('@/views/modules/winnInfo'), name: 'winnInfo', meta: { title: '中奖信息' } },
      { path: '/member', component: () => import('@/views/modules/member'), name: 'member', meta: { title: '用户会员' } },
      { path: '/employee', component: () => import('@/views/modules/employee'), name: 'employee', meta: { title: '员工信息' } },
    ]
  },
  {
    path: '/404',
    component: () => import('@/views/pages/404'),
    name: '404',
    meta: { title: '404未找到' },
    beforeEnter(to, from, next) {
      // 拦截处理特殊业务场景
      // 如果, 重定向路由包含__双下划线, 为临时添加路由
      if (/__.*/.test(to.redirectedFrom)) {
        return next(to.redirectedFrom.replace(/__.*/, ''))
      }
      next()
    }
  },
]


const router = new VueRouter({
  /*  mode: 'history', */
  base: process.env.BASE_URL,
  routes
})

// router.beforeEach((to, from, next) => {
//   if (sessionStorage.getItem('token')) {//有token 放行
//     next()
//   } else {
//     if (to.path === "/login") { //输入登录 放行  放他去登录
//       next()
//     } else {// 输入其他，让它跳转登录
//       next({ path: "/login" })
//     }
//   }

// })


export default router
